import React, { Component } from 'react'

export default class App extends Component {
  // constructor(){
  //   super()
  //   this.add=this.add.bind(this)
  // }
  state = {
    count: 0,
    age: 18,
    show: true
  }
  del = () => {
    this.setState({
      count: this.state.count - 1
    }, () => console.log(this.state))
  }
  add = () => {
    this.setState({
      count: this.state.count + 1
    }, () => console.log(this.state))
  }
  show = () => {
    this.setState({
      show: !this.state.show
    })
  }
  render() {
    return (
      <React.Fragment>
        <button onClick={() => this.del()}>-</button>
        <span>{this.state.count}</span>
        <button onClick={() => this.add()}>+</button><br />
        {/* <button onClick={this.show}>显示/隐藏</button>
        <p style={{ display: this.state.show ? 'block' : 'none' }}>数据</p><br /> */}
        <button onClick={this.show}>添加/删除</button>
        {this.state.show&&<div>数据</div>}
      </React.Fragment>
    )
  }
}
